package de.planethold.sevenloadj;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.w3c.dom.Element;


public class Item {
	public enum TYPE {VIDEO, IMAGE, AUDIO};
	
	private int views;
	private Calendar created;
	private String title;
	private String description;
	private Double averageRating;
	private List<String> tags;
	private String id;
	private String type;
	private String status;
	
	public Item(Element itemElement) {
		views = Integer.parseInt(itemElement.getElementsByTagName("views").item(0).getChildNodes().item(0).getNodeValue());
		created = Utiliy.getCalendar(itemElement.getElementsByTagName("created-at").item(0).getChildNodes().item(0).getNodeValue());
		title = itemElement.getElementsByTagName("title").item(0).getChildNodes().item(0).getNodeValue();
		if (itemElement.getElementsByTagName("description").item(0)==null || itemElement.getElementsByTagName("description").item(0).getChildNodes().item(0) == null) {
			description = "";
		} else {
			description = itemElement.getElementsByTagName("description").item(0).getChildNodes().item(0).getNodeValue();
		}
		averageRating = Double.parseDouble(itemElement.getElementsByTagName("average-rating").item(0).getChildNodes().item(0).getNodeValue());
		if (itemElement.getElementsByTagName("tags").item(0)!=null) {
			tags = Utiliy.createList((Element)itemElement.getElementsByTagName("tags").item(0), "tag");
		} else {
			tags = new ArrayList<String>();
		}
		id = itemElement.getAttribute("id");
		type = itemElement.getAttribute("type");
		status = itemElement.getAttribute("status");
	}
	
	public String toString() {
		return "views: " + views + "\n"
		+ "created: " + Utiliy.printCalendar(created) + "\n"
		+ "title: " + title + "\n"
		+ "description: " + description + "\n"
		+ "averageRating: " + averageRating + "\n"
		+ "tags:\n" + Utiliy.printList(tags) + "\n"
		+ "id: " + id + "\n"
		+ "type: " + type + "\n"
		+ "status: " + status + "\n"
		;
	}
}
